﻿using System;
using System.Data;
using DataAccess.Modules.Entity.Production;
using BusinessObject.Modules.Production;

namespace DataAccess.Modules.Model.Production
{
    public class ProductionCathegoryDescription : _ProductionCathegoryDescription, DataAccess.BaseObjects.IEntityModel
    {

        public DataTable SelectAll()
        {
            base.LoadAll();
            return this.DataTable;
        }

        public DataTable Select(BusinessLogic.BaseObjects.BusinessObject businessObject)
        {
            base.LoadByPrimaryKey(((Cathegory)businessObject).Id);
            return this.DataTable;
        }

        public void Insert(BusinessLogic.BaseObjects.BusinessObject businessObject)
        {
            var cathegory = (Cathegory)businessObject;

            base.AddNew();
            this.Name = cathegory.Name;
            this.Description = cathegory.Description;
            base.Save();
        }

        public int InsertIdentity(BusinessLogic.BaseObjects.BusinessObject businessObject)
        {
            var cathegory = (Cathegory)businessObject;

            base.AddNew();
            this.Name = cathegory.Name;
            this.Description = cathegory.Description;
            this.Save();

            return this.IdCathegory;
        }

        public void Update(BusinessLogic.BaseObjects.BusinessObject businessObject)
        {
            var cathegory = (Cathegory)businessObject;

            this.Name = cathegory.Name;
            this.Description = cathegory.Description;

            base.Save();
        }

        public void UpdateNoNulls(BusinessLogic.BaseObjects.BusinessObject businessObject)
        {
            var cathegory = (Cathegory)businessObject;

            if (cathegory.Name != null)
            {
                this.Name = cathegory.Name;
            }

            if (cathegory.Description != null)
            {
                this.Description = cathegory.Description;
            }

            base.Save();
        }

        public void Delete(BusinessLogic.BaseObjects.BusinessObject businessObject)
        {
            var cathegory = (Cathegory)businessObject;


        }

        public void DeleteAllReg()
        {
            if (base.LoadAll())
            {
                base.DeleteAll();
            }
        }
    }
}
